using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.MedicalDomain;
using ShivamEMR.Model.DataInterfaces.MedicalDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Medical.Controllers
{   
    public class TestGroupController : Controller
    {
		private readonly ITestGroupRepository testgroupRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public TestGroupController() //: this(new TestGroupRepository())
        {
            this.testgroupRepository = Registry.RepositoryFactory.GetTestGroupRepository();
        }

        public TestGroupController(ITestGroupRepository testgroupRepository)
        {
			this.testgroupRepository = testgroupRepository;
        }

        //
        // GET: /TestGroup/

        public ViewResult Index()
        {
            return View(testgroupRepository.All);//Including(testgroup => testgroup.Parent, testgroup => testgroup.Children, testgroup => testgroup.Tests));
        }

        //
        // GET: /TestGroup/Details/5

        public ViewResult Details(int id)
        {
            return View(testgroupRepository.Find(id));
        }

        //
        // GET: /TestGroup/Create

        public ActionResult Create()
        {
			ViewBag.PossibleParents = testgroupRepository.All;
            return View();
        } 

        //
        // POST: /TestGroup/Create

        [HttpPost]
        public ActionResult Create(TestGroup testgroup)
        {
            if (ModelState.IsValid) {
                testgroupRepository.InsertOrUpdate(testgroup);
                testgroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleParents = testgroupRepository.All;
				return View();
			}
        }
        
        //
        // GET: /TestGroup/Edit/5
 
        public ActionResult Edit(int id)
        {
			ViewBag.PossibleParents = testgroupRepository.All;
             return View(testgroupRepository.Find(id));
        }

        //
        // POST: /TestGroup/Edit/5

        [HttpPost]
        public ActionResult Edit(TestGroup testgroup)
        {
            if (ModelState.IsValid) {
                testgroupRepository.InsertOrUpdate(testgroup);
                testgroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleParents = testgroupRepository.All;
				return View();
			}
        }

        //
        // GET: /TestGroup/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(testgroupRepository.Find(id));
        }

        //
        // POST: /TestGroup/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var t = testgroupRepository.Find(id);
            testgroupRepository.Delete(t);
            testgroupRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

